﻿using SSCAI.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SSCAI.Model
{
    public class LotteryModel
    {
        public int Id { get; set; }
        public string Issue { get; set; }
        public string WinningNumber { get; set; }
        public string ModifiedTime { get; set; }
        public bool IsValid { get; set; }
        public LotteryModel LastIssueLottery { get; set; }

        /// <summary>
        /// 从大到小排列--左到右 4321
        /// </summary>
        public string BigToSmall
        {
            get
            {
                return string.Join(string.Empty,
                    CalculateHelper.QickSort(
                                                    new int[] { 
                                                    this.GeWei, 
                                                    this.ShiWei, 
                                                    this.BaiWei, 
                                                    this.QianWei }
                                                ));
            }
        }

        /// <summary>
        /// 从小到大排列--左到右 1234
        /// </summary>
        public string SmallToBig
        {
            get
            {
                return string.Join(string.Empty,
                    CalculateHelper.QickSort(
                                                    new int[] { 
                                                    this.GeWei, 
                                                    this.ShiWei, 
                                                    this.BaiWei, 
                                                    this.QianWei },
                                                    1
                                                ));
            }
        }

        /// <summary>
        /// 4D和尾
        /// </summary>
        public int FourDSumTail
        {
            get
            {
                return this.FourDSum % 10;
            }
        }

        /// <summary>
        /// 012路
        /// </summary>
        public string Number012
        {
            get
            {
                return string.Concat(this.QianWei % 3, this.BaiWei % 3, this.ShiWei % 3, this.GeWei % 3);
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public string Number01
        {
            get
            {
                return string.Concat(this.QianWei % 2, this.BaiWei % 2, this.ShiWei % 2, this.GeWei % 2);
            }
        }

        /// <summary>
        /// 0123路
        /// </summary>
        public string Number0123
        {
            get
            {
                return string.Concat(this.QianWei % 4, this.BaiWei % 4, this.ShiWei % 4, this.GeWei % 4);
            }
        }

        /// <summary>
        /// 01234路
        /// </summary>
        public string Number01234
        {
            get
            {
                return string.Concat(this.QianWei % 5, this.BaiWei % 5, this.ShiWei % 5, this.GeWei % 5);
            }
        }

        /// <summary>
        /// 4D号码
        /// </summary>
        public string FourDNumber
        {
            get
            {
                return this.WinningNumber.Substring(1, 4);
            }
        }

        /// <summary>
        /// 4D和值
        /// </summary>
        public int FourDSum
        {
            get
            {
                return this.GeWei + this.ShiWei + this.BaiWei + this.QianWei;
            }
        }

        /// <summary>
        /// 个位
        /// </summary>
        public int GeWei
        {
            get
            {
                return Convert.ToInt16(this.WinningNumber.Substring(4, 1));
            }
        }

        /// <summary>
        /// 十位
        /// </summary>
        public int ShiWei
        {
            get
            {
                return Convert.ToInt16(this.WinningNumber.Substring(3, 1));
            }
        }

        /// <summary>
        /// 百位
        /// </summary>
        public int BaiWei
        {
            get
            {
                return Convert.ToInt16(this.WinningNumber.Substring(2, 1));
            }
        }

        /// <summary>
        /// 千位
        /// </summary>
        public int QianWei
        {
            get
            {
                return Convert.ToInt16(this.WinningNumber.Substring(1, 1));
            }
        }

        /// <summary>
        /// 万位数字
        /// </summary>
        public int WanWei
        {
            get
            {
                return Convert.ToInt16(this.WinningNumber.Substring(0, 1));
            }
        }

        /// <summary>
        /// 4d 位差 比如 开奖号 *7641 跨度 1，2，3，6
        /// </summary>
        public string FourDDeviation
        {
            get
            {
                return string.Concat(
                                        Math.Abs(this.QianWei - this.BaiWei).ToString(),
                                        ",",
                                        Math.Abs(this.BaiWei - this.ShiWei).ToString(),
                                        ",",
                                        Math.Abs(this.ShiWei - this.GeWei).ToString(),
                                        ",",
                                        Math.Abs(this.QianWei - this.GeWei).ToString()
                                     );
            }
        }

        /// <summary>
        /// 4d 跨度 
        /// </summary>
        public string FourDSpan
        {
            get
            {
                return LastIssueLottery == null ? "" : string.Concat(

                                        Math.Abs(this.LastIssueLottery.QianWei - this.QianWei).ToString(),
                                        ",",
                                        Math.Abs(this.LastIssueLottery.BaiWei - this.BaiWei).ToString(),
                                        ",",
                                        Math.Abs(this.LastIssueLottery.ShiWei - this.ShiWei).ToString(),
                                        ",",
                                        Math.Abs(this.LastIssueLottery.GeWei - this.GeWei).ToString()
                                     );
            }
        }

        /// <summary>
        /// 乘积，不乘0
        /// </summary>
        public int Product
        {
            get
            {
                int product = 1;

                int[] numbers = { this.QianWei, this.BaiWei, this.ShiWei, this.GeWei };

                for (int i = 0; i < numbers.Length; i++)
                {

                    if (numbers[i] != 0)
                    {
                        product *= numbers[i];
                    }
                }

                return product;
            }
        }

        public int LastTwoNumbsSubtraction
        {
            get
            {
                return Math.Abs(this.ShiWei - this.GeWei);
            }
        }

        public int LastTwoNumsSum
        {
            get
            {
                return this.GeWei + this.ShiWei;
            }
        }
    }
}
